/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* Copyright 2002-2003 by Mark Wolgemuth, All rights reserved.             */
/* Copyright 2002-2003 by Employease, Inc.  All rights reserved.           */
/*                                                                         */
/* Redistribution and use in source and binary forms, with or without      */
/* modification, are permitted provided that the following conditions      */
/* are met:                                                                */
/*                                                                         */
/*    1. Redistributions of source code must retain the above copyright    */
/* notice, this list of conditions and the following disclaimer.           */
/*    2. Redistributions in binary form must reproduce the above copyright */
/* notice, this list of conditions and the following disclaimer in the     */
/* documentation and/or other materials provided with the distribution.    */
/*                                                                         */
/* THIS SOFTWARE IS PROVIDED BY THE MOD_ATHENA PROJECT ``AS IS'' AND ANY   */
/* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE       */
/* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR      */
/* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FREEBSD PROJECT OR        */
/* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,   */
/* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,     */
/* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR      */
/* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY     */
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT            */
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE   */
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.    */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#ifndef ATH_LIST_H
#define ATH_LIST_H

#include <sys/types.h>

#include <ctype.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "ath_list_types.h"

#include <apr_pools.h>

/* the _r function versions are reentrant, using a node for context */
/* functions without _r are (if there is a corresponding _r func) */
/* are wrapper funcs that use the object's own ctx node for context */
/* if no _r func exists, the func is always thread safe */
/* _r (ctx ptr) is used to track context (position) local to the caller */
/* ath_list.c */
#ifndef USE_POOLS
ath_list *    ath_list_alloc();
ath_list *    ath_list_alloc_r(ath_node **ctx);
#endif 
void          ath_list_init(ath_list *list);
void          ath_list_init_r(ath_list *list, ath_node **ctx);
void          ath_list_free(ath_list *list);
void          ath_list_free_r(ath_list *list, ath_node **ctx);
int           ath_list_add(ath_list *list, void *pd); 
int           ath_list_add_r(ath_list *list, void *pd, ath_node **ctx); 
apr_int64_t   ath_list_size(ath_list *list);
int           ath_list_delete_cur(ath_list *list);
int           ath_list_delete_cur_r(ath_list *list, ath_node **ctx);
void          ath_list_remove_cur(ath_list *list);
void          ath_list_remove_cur_r(ath_list *list, ath_node **ctx);
void          ath_list_remove_prev(ath_list *list);
void          ath_list_remove_prev_r(ath_list *list, ath_node **ctx);
void *        ath_list_getnext(ath_list *list);
void *        ath_list_getnext_r(ath_list *list, ath_node **ctx);
void *        ath_list_popnext(ath_list *pl);
void *        ath_list_popnext_r(ath_list *pl, ath_node **ctx);
void          ath_list_rewind(ath_list *list);
void          ath_list_rewind_r(ath_list *list, ath_node **ctx);
void          ath_list_tohead(ath_list *list);
void          ath_list_tohead_r(ath_list *list, ath_node **ctx);
int           ath_list_hasnext(ath_list *list);
int           ath_list_hasnext_r(ath_list *list, ath_node **ctx);
int           ath_list_at_head(ath_list *list);
int           ath_list_at_head_r(ath_list *list, ath_node **ctx);
void *        ath_list_idx(ath_list *pl, int idx);
int           ath_list_lock(ath_list *pl);
int           ath_list_unlock(ath_list *pl);
void          ath_list_debug_lock(ath_list *pl);

ath_list *    ath_list_ap_alloc(apr_pool_t *p);
ath_list *    ath_list_ap_alloc_r(apr_pool_t *p, ath_node **ctx);
int           ath_list_ap_add(apr_pool_t *pool, ath_list *pl, 
			      void *pd);
int           ath_list_ap_add_r(apr_pool_t *pool, ath_list *pl, 
				void *pd, ath_node **ctx);
int           ath_list_ap_add_tail(apr_pool_t *pool, ath_list *pl, 
				   void *p_data);

/* define normal looking aliases now that we force pool use */
#define       ath_list_alloc(p)          ath_list_ap_alloc(p)
#define       ath_list_alloc_r(p,c)      ath_list_ap_alloc_r(p,c)
#define       ath_list_add(p,l,d)        ath_list_ap_add(p,l,d)
#define       ath_list_add_r(p,l,d,c)    ath_list_ap_add_r(p,l,d,c)
#define       ath_list_add_tail(p,l,d)   ath_list_ap_add_tail(p,l,d)

/*
 * DEBUGGING FLAG for ASSERT
 * 
 */

#ifndef   ATH_DEBUG
#ifndef   ASSERT
#define   ASSERT(p) ((void)0)
#endif /* ASSERT */

#else /* ATH_DEBUG */

#ifndef   ASSERT
#define   ASSERT(e) (assert(e))
#endif /* ASSERT */
#endif /* ATH_DEBUG */

#endif // ATH_LIST_H
